package constant

import "strings"

const (
	UnknownError = -1
	Success      = 0

	// api side error, starts with 1000-
	TooManyData = 10001

	// ims side error, starts with 2000-
	AdminNotExists        = 20001
	InvalidVCode          = 20002
	InvalidSmsCode        = 20003
	ApiNotRegisted        = 20004
	ModuleAccessDenied    = 20005
	NotLogin              = 20006
	WrongUsernamePassword = 20007

	// admind side error, starts with 3000-
	ErrorDevNoResp           = 30001 // 设备1分钟内无应答
	ErrorDevNoRespAfterResnd = 30002 // 重发2次仍无应答
	ErrorDevDisConnect       = 30003 // 设备连接已断开
	ErrorSaveDBFail          = 30004 // 保存数据库失败
	ErrorJsonUnmarshFail     = 30005 // str到json解析失败
	ErrorParamNotEnough      = 30006 // 参数不全
	ErrorTimeout             = 30007 // 设备响应超时
	ErrorSiteidNotExist      = 30008 // 数据库中站点id不存在
	ErrorParseFilepath       = 30009 // 文件路径不合法，不在服务器上
	ErrorOpenFile            = 30010 // 打开文件出错
	ErrorReadFile            = 30011 // 读文件出错
	ErrorParamWrong          = 30012 // 参数值错误
	ErrorUnsupportedCmd      = 30013 // 不支持的命令字
	ErrorLength              = 30014 // 密码长度错误
	ErrorUserName            = 30015 // 用户名重复
	ErrorDB                  = 30016 // 数据库错误
	ErrorCommodity           = 30017 // 商品不存在
	ErrorNotUser             = 30018 //用户不存在
	ErrorStory               = 30019 //商铺不存在
	ErrorUnknown             = 39999 // 其他错误

)

func TranslateErrCode(code int, extra ...string) string {
	var msg string
	switch code {
	case UnknownError:
		msg = "Unknown error"
	case AdminNotExists:
		msg = "管理员不存在"
	case WrongUsernamePassword:
		msg = "用户名或密码错误"
	case NotLogin:
		msg = "用户未登录"
	case InvalidVCode:
		msg = "验证码错误"
	case InvalidSmsCode:
		msg = "无效的手机验证码"
	case ErrorDevNoResp:
		return "设备1分钟内无应答"
	case ErrorDevNoRespAfterResnd:
		return "重发3次仍无应答"
	case ErrorDevDisConnect:
		return "设备连接已断开"
	case ErrorSaveDBFail:
		return "保存数据库失败"
	case ErrorJsonUnmarshFail:
		return "str到json解析失败"
	case ErrorParamNotEnough:
		return "参数不全"
	case ErrorTimeout:
		return "设备响应超时"
	case ErrorSiteidNotExist:
		return "数据库中站点id不存在"
	case ErrorParseFilepath:
		return "文件路径不合法，不在服务器上"
	case ErrorOpenFile:
		return "打开文件出错"
	case ErrorReadFile:
		return "读文件出错"
	case ErrorParamWrong:
		return "参数值错误"
	case ErrorUnsupportedCmd:
		return "不支持的命令字"
	case ErrorUnknown:
		return "其他未知错误"
	case TooManyData:
		return "数据太多"
	case ErrorLength:
		return "密码长度错误"
	case ErrorUserName:
		return "用户名重复"
	case ErrorDB:
		return "数据库访问错误"
	case ErrorCommodity:
		return "商品不存在"
	case ErrorNotUser:
		return "用户不存在"
	case ErrorStory:
		return "商铺不存在"
	default:
	}

	if len(extra) > 0 {
		msg = msg + ": " + strings.Join(extra, ",")
	}
	return msg
}
